package com.it.gw.modules.main.viewmodel

import ADNMVo
import VersionVo
import com.it.common.bean.CommonBean
import com.it.common.livedata.UnPeekLiveData
import com.it.data.base.BaseViewModel
import com.it.data.network.Api
import com.it.data.network.rsp.DictionariesVo
import com.it.data.network.rsp.GQYWXXVo
import com.it.data.network.rsp.MenuVo
import com.it.data.network.rsp.NodeVo
import com.it.data.network.rsp.QuaTypeVo
import com.it.data.network.rsp.SttpVo

class MainViewModel : BaseViewModel() {
    companion object {
        const val TAG = "MainViewModel"
    }

    val menuVoListLiveData by lazy { UnPeekLiveData<CommonBean<List<MenuVo>>>() }
    val nodeVoListLiveData by lazy { UnPeekLiveData<CommonBean<List<NodeVo>>>() }
    val sttpVoListLiveData by lazy { UnPeekLiveData<CommonBean<List<SttpVo>>>() }
    val gqywxxVoLiveData by lazy { UnPeekLiveData<CommonBean<GQYWXXVo>>() }
    val quaTypeVoListLiveData by lazy { UnPeekLiveData<CommonBean<List<QuaTypeVo>>>() }

    val versionLiveData by lazy { UnPeekLiveData<CommonBean<VersionVo>>() }

    fun findMenuListByUserid(userId: String) {
        requestCommit(request = {
            Api.apiClient().findMenuListByUserid(userId = userId)
        }, resp = {
            menuVoListLiveData.postValue(it)
        })
    }

    fun getNodeByAd(depId: String, resp: ((CommonBean<List<NodeVo>>) -> Unit)? = null) {
        requestCommit(request = {
            Api.apiClient().getNodeByAd(depId = depId)
        }, resp = {
            resp?.invoke(it)
            nodeVoListLiveData.postValue(it)
        })
    }

    fun getSttp(resp: ((CommonBean<List<SttpVo>>) -> Unit)? = null) {
        requestCommit(request = {
            Api.apiClient().getSttp()
        }, resp = {
            resp?.invoke(it)
            sttpVoListLiveData.postValue(it)
        })
    }

    fun getGQYWXX(STCD: String) {
        requestCommit(request = {
            Api.apiClient().getGQYWXX(STCD = STCD)
        }, resp = {
            gqywxxVoLiveData.postValue(it)
        })
    }

    /**
     *
     * @param sttp String? 测站类型
     * @param resp Function1<CommonBean<List<QuaTypeVo>>, Unit>?
     */
    fun getQuaType(sttp: String? = null, resp: ((CommonBean<List<QuaTypeVo>>) -> Unit)? = null) {
        requestCommit(request = {
            Api.apiClient().getQuaType(sttp = sttp)
        }, resp = {
            resp?.invoke(it)
            quaTypeVoListLiveData.postValue(it)
        })
    }

    /**
     * 水利基础要素，获取字典
     * @param type String
     * @param resp Function1<CommonBean<List<WellUseTypeVo>>, Unit>?
     */
    fun wellUseType(
        type: String,
        resp: ((CommonBean<List<DictionariesVo>>) -> Unit)? = null
    ) {
        requestCommit(request = {
            Api.apiClient().getDictionaries(type = type)
        }, resp = {
            resp?.invoke(it)
        })
    }


    fun getShiAddvcd(
        resp: ((CommonBean<List<ADNMVo>>) -> Unit)? = null
    ) {
        requestCommit(request = {
            Api.apiClient().getShiAddvcd()
        }, resp = {
            resp?.invoke(it)
        })
    }

    fun getTuanAddvcd(
        id: String,
        resp: ((CommonBean<List<ADNMVo>>) -> Unit)? = null
    ) {
        requestCommit(request = {
            Api.apiClient().getTuanAddvcd(id)
        }, resp = {
            resp?.invoke(it)
        })
    }

    fun version(
    ) {
        requestCommit(request = {
            Api.apiClient().version()
        }, resp = {
            versionLiveData.postValue(it)
        })
    }

}